//
//  HWHeavyLiveCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/24.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWHeavyLiveCell: UICollectionViewCell {
    var bgImageView:UIImageView!
    var logoImageView:UIImageView!
    var nameLabel:UILabel!
    var alphaView:UIView!
    var peopleImageView:UIImageView!
    var peopleLabel:UILabel!
    var model:HWHomeTuiJianModel? {
        didSet {
            bgImageView.sd_setImage(with: URL(string: model?.image ?? ""), completed: nil)
            logoImageView.sd_setImage(with: URL(string: model?.icon ?? ""), completed: nil)
            nameLabel.text = model?.name
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWHeavyLiveCell {
    private func initUI() -> Void {
        contentView.backgroundColor = .clear
        bgImageView = UIImageView()
        bgImageView.backgroundColor = .red
        bgImageView.contentMode = .scaleAspectFill
        bgImageView.layer.masksToBounds = true
        bgImageView.layer.cornerRadius = 7*widthScale
        contentView.addSubview(bgImageView)
        
        alphaView = UIView()
        alphaView.frame = CGRect(x: 0, y: 0, width: 168*widthScale, height: 27*widthScale)
//        alphaView.backgroundColor = .colorWithAlphaHexString(hexString: "#2F2F2F", alpha: 0.16)
//        alphaView.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#7B7B7B", alpha: 0.2).cgColor
//        alphaView.layer.shadowOffset = CGSize(width: 0, height: 3)
//        alphaView.layer.shadowRadius = 0
//        alphaView.layer.shadowOpacity = 1
        let blur = UIBlurEffect(style: .light)
        let blurView = UIVisualEffectView(effect: blur)
        blurView.frame = CGRect(x: 0, y: 0, width: 168*widthScale, height: 27*widthScale)
        blurView.backgroundColor = .colorWithAlphaHexString(hexString: "#2F2F2F", alpha: 0.16)
        alphaView.addSubview(blurView)
        bgImageView.addSubview(alphaView)
//        UIColor.gradientColor(view: alphaView, colors: [UIColor.colorWithAlphaHexString(hexString: "#FFFFFF", alpha: 0).cgColor,
//                                                            UIColor.colorWithAlphaHexString(hexString: "#000000", alpha: 1).cgColor,],start: CGPoint(x: 0, y: 0),end: CGPoint(x: 0, y: 1))
        
        logoImageView = UIImageView()
        logoImageView.layer.cornerRadius = 8*widthScale
        logoImageView.layer.masksToBounds = true
        bgImageView.addSubview(logoImageView)
        
        nameLabel = HWLabel.createLabel(title: "", color: "#FFFFFF", font: 10*widthScale)
        nameLabel.numberOfLines = 1
        bgImageView.addSubview(nameLabel)
        
        
        peopleLabel = HWLabel.createBoldLabel(title: "", color: "#FFFFFF", font: 10*widthScale)
        bgImageView.addSubview(peopleLabel)
        
        peopleImageView = UIImageView()
        bgImageView.addSubview(peopleImageView)
    }
    
    private func initFrame() -> Void {
        bgImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        alphaView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(27*widthScale)
        }
        
        logoImageView.snp.makeConstraints { make in
            make.left.equalTo(4*widthScale)
            make.bottom.equalTo(-4*widthScale)
            make.width.height.equalTo(20*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(logoImageView.snp.right).offset(4*widthScale)
            make.centerY.equalTo(logoImageView)
            make.right.equalTo(peopleImageView.snp.left).offset(-11*widthScale)
        }
        
        peopleLabel.snp.makeConstraints { make in
            make.right.equalTo(-6*widthScale)
            make.centerY.equalTo(logoImageView)
        }
        
        peopleImageView.snp.makeConstraints { make in
            make.right.equalTo(peopleLabel.snp.left).offset(-3*widthScale)
            make.centerY.equalTo(logoImageView)
            make.width.height.equalTo(12*widthScale)
        }
        
    }
}
